Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generated Pull Request for feat/user-management #326

Merged
merged 45 commits into from
Feb 2, 2024

Conversation

github-actions[bot]
Copy link
Contributor

Pulling 'feat/user-management into develop. Please review and merge.

The import path for the slices package has been updated from
"k8s.io/utils/strings/slices" to "golang.org/x/exp/slices". This change
was made to ensure that the correct package is being imported and used
in the code.
…n method

This commit adds a new file `client.go` under the
`internal/logto/client` package. The file contains the implementation of
a `Client` struct and an `AccessToken` method. The `Client` struct has
two fields: `baseURL` and `httpClient`. The `AccessToken` method makes a
POST request to the `/oidc/token` endpoint with the provided user, pass,
and resource parameters. It returns the access token as a string or an
error if any occurred during the request or response handling. This
addition allows for easier integration with external services that
require access tokens for authentication.
The CreateAccessToken function is added to the cli package. This
function uses the logto client to generate an access token based on the
provided app ID, app secret, and API resource. If successful, it prints
the access token to the console. This feature allows users to easily
generate access tokens for authentication purposes.
…nagement

The logto command line application is added to provide management
functionalities for logto instances. It includes commands such as
creating a new logto access token. The application accepts various flags
for configuring the endpoint, log level, log format, and log file. The
application also sets up a logger using the provided flags before
executing any commands.
…v2.7.0

The go.mod file has been updated to include an indirect dependency on
the github.com/Jeffail/gabs/v2 package at version v2.7.0. This
dependency is added to fulfill the requirements of the project and
ensure compatibility with other dependencies.
… a new user

The CreateUser method is added to the Client struct to allow the
creation of a new user. It takes a token string and a pointer to an
APIUsersPostReq struct as parameters. It sends a POST request to the
"/api/users" endpoint with the user data in JSON format. The response is
then decoded and the user ID is returned. This new method provides a
convenient way to create users in the client application.
fix(client.go): add missing return statement in reqToResponse function
The missing closing brace in the AccessToken function caused a compilation error. Adding the missing return statement in the reqToResponse function ensures that the function returns the expected response or error.
…sToken method

The duplicate code in the AccessToken method has been removed by calling
the reqToResponse method instead of making the HTTP request directly.
This improves code readability and maintainability. Additionally, the
error handling in the AccessToken method has been fixed to return the
original error instead of wrapping it in a new error message.
…ing users from an input file

The "import-user" command is added to the logto CLI tool, allowing users
to import user data from an input file. This new command provides a
convenient way to bulk import user information into the logto system.
… for improved naming conventions

The accessTokenResp struct has been renamed to AccessTokenResp to follow
proper naming conventions. The AccessToken method now takes user, pass,
and resource as separate parameters instead of a single string parameter
for improved readability. The method now returns a pointer to
AccessTokenResp and an error instead of just a string and an error.
The ImportUser function is added to the cli package. This function is
responsible for importing a user into the system. It uses the logto
client package to interact with the logto service. The function takes in
a cli.Context as a parameter. It retrieves the logger from the registry,
creates a new logto client, and obtains an access token using the
provided app ID, app secret, and API resource. It then proceeds to
create a new user using the logto client's CreateUser method, passing in
the necessary user information. If any errors occur during the process,
the function returns an error message. Otherwise, it logs the user ID
and returns nil.
…d consistency

The variable 'atoken' has been renamed to 'aresp' to improve clarity and
consistency. All references to 'atoken' have been updated to use
'aresp.AccessToken' to correctly access the access token value.
…che/v3 v3.1.0

The go.mod file has been updated to include two new indirect
dependencies. The first one is github.com/jellydator/ttlcache/v3 v3.1.0,
which is added to the list of required modules. The second one is
golang.org/x/sync v0.1.0, which is also added as an indirect dependency.
These changes were made to ensure that the project has the necessary
dependencies for its functionality.
The registry.go file has been modified to add support for a TTL cache.
The import statement for the ttlcache package has been added. The
constant TTLCacheKey has been defined to store the key for the TTL cache
in the registry.
Two new functions, SetTTLCache and GetTTLCache, have been added to the
registry. SetTTLCache allows setting the TTL cache in the registry, and
GetTTLCache allows retrieving the TTL cache from the registry. These
functions provide convenient access to the TTL cache functionality in
the registry.
The logto command now supports a TTL cache for storing temporary data.
This is achieved by adding the `github.com/jellydator/ttlcache/v3`
package as an import and creating a new TTL cache instance in the `main`
function. The TTL cache instance is then set in the registry using the
`SetTTLCache` function.
In the `registry` package, the `SetTTLCache` function has been fixed to
use the correct type for the `tcache` parameter, which is
`*ttlcache.Cache[string, int]`. This ensures that the TTL cache is
correctly stored in the registry.
return uresp, nil
}

func (clnt *Client) CreateUser(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method Client.CreateUser has 5 return statements (exceeds 4 allowed).

…, int]() to ttlcache.New[string, string]() to match the expected type in SetTTLCache function

The type of the tcache variable in main.go is changed to match the
expected type in the SetTTLCache function. Similarly, the type of the
tcache parameter in the SetTTLCache function is changed to match the
type used in the GetTTLCache function.
…function for reusability and readability

The code in the ImportUser function has been refactored to extract the
logic for retrieving the access token into a separate function called
retrieveToken. This improves the readability and reusability of the
code. Additionally, a caching mechanism has been implemented using the
ttlcache library to store the access token, reducing the number of API
calls required to retrieve a new token.
…k to set up ttlcache and reader

The code related to initializing and setting the ttlcache has been
removed as it is no longer needed. The import-user command has been
added with an input flag to specify the input csv file. A before hook
has been added to set up the ttlcache and reader before executing the
import-user command.
… existence

The CheckUser method is added to the Client struct to provide a way to
verify if a user exists in the system. It takes a token and an email as
parameters and queries the API to check if a user with the given email
exists. The method constructs a GET request with the necessary
parameters and headers, sends the request, and decodes the response to
check if the user exists. If the user is found, the method returns true,
otherwise it returns false.
… function

The 'APIUsersSearchRes' struct now includes an 'Id' field to include the
user ID in the response. The 'CheckUser' function signature is modified
to return the user ID along with the boolean result. The error messages
in the 'CheckUser' function are updated to provide better clarity. The
'CheckUser' function now returns the user ID along with the boolean
result.
The CheckUserWithUserName method is added to the Client struct. This
method takes in a token, email, and username as parameters and checks if
a user with the given email and username exists. It makes a GET request
to the API's users endpoint with the specified query parameters and
returns a boolean indicating if the user exists, the user's ID, and any
error that occurred during the process.
…UserName function

The "search.primaryEmail" and "join" parameters were removed from the
params variable in the CheckUserWithUserName function.
…archRes struct

The 'Email' field in the APIUsersSearchRes struct has been renamed to
'UserName' to better reflect its purpose. The CheckUserWithUserName
function has been updated to use the 'UserName' parameter instead of the
'Email' parameter when searching for a user.
…gs for token generation

The functions RandomInt, FixedLenRandomInt, and FixedLenRandomString are
added to the user.go file in the cli package. These functions utilize
the crypto/rand package to generate random numbers and strings of fixed
ength. These functions will be used for token generation in the
application.
…haracters and spaces from the concatenated first and last name

The normalizeUserName function is added to remove special characters and
spaces from the concatenated first and last name.
This commit adds support for importing users from a CSV file. The changes include:
- Importing the "encoding/csv" package to read the CSV file
- Adding a loop to read each record from the CSV file
- Checking if the user is valid before creating it
- Checking if the user already exists before creating it
- Creating the user with the provided information if it doesn't exist
return uresp, nil
}

func (clnt *Client) CheckUserWithUserName(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method Client.CheckUserWithUserName has 7 return statements (exceeds 4 allowed).

return true, usrs[index].Id, nil
}

func (clnt *Client) CheckUser(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method Client.CheckUser has 7 return statements (exceeds 4 allowed).

return uresp, nil
}

func (clnt *Client) CheckUserWithUserName(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return true, usrs[index].Id, nil
}

func (clnt *Client) CheckUser(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

…andomString and ImportUser functions

The FixedLenRandomInt and FixedLenRandomString functions are added to
generate random strings of fixed length using digits and alphanumeric
characters respectively. The ImportUser function is added to import user
data from a CSV file and create users in a logto system. It retrieves
the logger and TTL cache from the registry, creates a CSV reader, a
logto client, and iterates over each record in the CSV file. It checks
if the user record is valid, retrieves the authentication token, checks
if the user already exists by email and username, normalizes the
username, and creates the user in the logto system.
…bility and readability

The commonHeader function is extracted to improve code reusability and
readability. It sets the Content-Type, Accept, and Authorization headers
for an HTTP request. This extraction allows for easier maintenance and
avoids code duplication when setting headers in multiple places.
…g logic into a separate function

The code in the client.go file has been refactored to simplify the logic
of setting common headers for HTTP requests. The common header setting
logic has been extracted into a separate function called commonHeader,
which improves code readability and reduces duplication.
…om data for user patch requests

The APIUsersPatchCustomData struct is added to represent the custom data
fields that can be included in a user patch request. This allows for
more flexibility in updating user information by including additional
fields such as profession, job title, institution, address, etc.
This commit adds a new function `AddCustomUserInformation` to the
`Client` struct in the `client.go` file. This function allows the client
to add custom information to a user by sending a PATCH request to the
appropriate API endpoint. The function takes in the user's token, user
ID, and the custom data to be added. It converts the custom data to
JSON, creates a PATCH request with the necessary headers and content,
and sends the request to the API. Any errors encountered during the
process are handled and returned as an error.
The typo in the field name "Contry" has been fixed to "Country" to
accurately represent the country field in the APIUsersPatchCustomData
struct. Additionally, a new field "Phone" has been added to the struct
to include phone number information.
The code now includes logic to import user custom data from a CSV file.
The `ImportUser` function has been updated to handle the import process.
It now parses the CSV file and creates a new user with the provided
information. Additionally, it sets the `isSubscribed` flag based on the
value in the CSV file and adds the custom data to the user using the
`AddCustomUserInformation` method from the `lclient` client.
If any errors occur during the import process, the function will exit
with an error message. Debug logs are also added to provide information
about the creation of the custom data for each user.
…method

The URL construction in the AddCustomUserInformation method was
incorrect. The base URL was not being properly appended to the request
URL. This fix ensures that the base URL is correctly included in the
request URL.
…ustomData parameter

The ImportUser function in user.go has been refactored to improve code
readability and maintainability. Instead of passing individual
parameters for CustomData, a struct named AdditionalUserInformation has
been created to encapsulate all the fields.
The 'logto' file is now being ignored by Git to prevent it from being
tracked and committed.
The depguard linter was causing unnecessary noise in the linting
process. It was commented out to streamline the linting process and
focus on more critical issues. This change will make the linting output
more manageable and meaningful.
… for better code readability

The setupCliLogger and setupTTLCache functions were extracted from the
main function to improve code readability and maintainability. This
makes the code easier to understand and modify in the future. The
'logto' entry was removed from .gitignore as it's no longer needed,
keeping the .gitignore file clean and up-to-date.
…eadability and maintainability

The ImportUser function in user.go was becoming too large and complex,
making it difficult to understand and maintain. To improve this, the
logic for processing CSV records, creating users, and adding custom user
information has been extracted into separate functions.
… for better readability and maintainability

The LoadStrain function was too large and complex, making it difficult
to understand and maintain. It has been refactored into smaller, more
manageable functions. Each function now has a single responsibility,
improving the readability and maintainability of the code.
return updateStrain(strain, logger, client)
}

func createStrain(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return nil
}

func updateStrain(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

…for better readability and maintainability

The previous implementation of the setStrainInputReader function in
strain.go was quite lengthy and repetitive. The same operations were
being performed for different types of files. This commit refactors the
function by extracting the repetitive code into separate functions.
return nil
}

func openLocalFiles() error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function openLocalFiles has 5 return statements (exceeds 4 allowed).

return nil
}

func getS3Files() error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getS3Files has 5 return statements (exceeds 4 allowed).

return nil
}

func openLocalFiles() error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return nil
}

func getS3Files() error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

…ction calls into multiple lines

The changes were made to improve the readability of the code. Long
function calls and declarations were broken down into multiple lines.
This makes the code easier to read and understand, especially for
developers who are new to the project or are not familiar with the
specific section of the code.
… readability and maintainability

The code in the LoadPlasmid function was refactored into smaller, more
manageable functions. This was done to improve the readability of the
code and make it easier to maintain. The logic for initializing the
AnnotatorLookup, PubLookup, and GeneLookup was extracted into separate
functions. The logic for processing each plasmid was also extracted into
a separate function.
return gl, nil
}

func processNextPlasmid(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function processNextPlasmid has 6 return statements (exceeds 4 allowed).

return true, nil
}

func createPlasmid(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return nil
}

func updatePlasmid(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

… functions for better readability and maintainability

The LoadStrainSynProp function was too large and complex, making it
difficult to understand and maintain. It has been refactored into
smaller, more manageable functions. This change improves the readability
of the code and makes it easier to test and debug.
…TimestampProto function implementation

The unused protobuf imports were removed to clean up the code and
improve readability. The TimestampProto function was refactored to use
the new timestamppb.New function from the
google.golang.org/protobuf/types/known/timestamppb package. This change
was made because the previous implementation using ptypes.TimestampProto
is now deprecated. The error messages in the delAnnotationGroup function
were also reformatted for better readability.
Copy link

codeclimate bot commented Feb 2, 2024

Code Climate has analyzed commit fa3d8d6 and detected 15 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 7
Duplication 8

View more on Code Climate.

@cybersiddhu cybersiddhu added the automerge automerge pull request label Feb 2, 2024
@kodiakhq kodiakhq bot merged commit ebcaf1c into develop Feb 2, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge automerge pull request size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant